/*
std::atomic<int> counter(0)
counter.fetch_add(2)
counter.fetch_sub(1)
load()
store()
*/

#include<atomic>
#include<iostream>
#include<pthread.h>

std::atomic<int> counter(0);

void* increment(void* arg)
{
	for(int i = 0; i < 100000; i++)
	{
		counter++;
	}

	return nullptr;
}


int main(int argc,char** argv)
{
	pthread_t t1,t2;

	pthread_create(&t1,nullptr,increment,nullptr);
	pthread_create(&t2,nullptr,increment,nullptr);

	pthread_join(t1,nullptr);
	pthread_join(t2,nullptr);

	std::cout << "final counter val:" << counter << std::endl;

	return 0;
}











